package com.wxd.action;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;

import org.apache.struts2.ServletActionContext;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.rtf.RtfWriter2;
import com.opensymphony.xwork2.ActionSupport;
import com.wxd.bean.UserInfo;
import com.wxd.service.ChartDataService;
import com.wxd.service.impl.ChartDataServiceImpl;

public class ChartDataAction extends ActionSupport {
	private ChartDataService service = new ChartDataServiceImpl();
	private InputStream inputStream;

	public InputStream getResult() {
		return this.inputStream;
	}

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

	// 根据公司分组来获得设备的列表
	public String getDevListGroupCompany() throws Exception {
		JSONArray resultArray = service.getDevListGroupCompany();
		this.inputStream = new ByteArrayInputStream(resultArray.toString()
				.getBytes("utf-8"));

		return SUCCESS;
	}

	public String singleDevChartData() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String devCode = request.getParameter("devCode");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");

		StringBuffer result = service.singleDevChartData(devCode, startTime,
				endTime);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}

	public String devSpiChartData() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String devSpi = request.getParameter("devSpi");
		devSpi = URLDecoder.decode(devSpi, "utf-8");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");

		StringBuffer result = service.devSpiChartData(devSpi, startTime,
				endTime);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}

	public String devUnitChartData() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String devUnit = request.getParameter("devUnit");
		devUnit = URLDecoder.decode(devUnit, "utf-8");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");

		StringBuffer result = service.devUnitChartData(devUnit, startTime,
				endTime);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}

	public String spiRunDistanceCompareChartData() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();

		String year = request.getParameter("year");
		Calendar instance = Calendar.getInstance();
		int nYear = instance.get(Calendar.YEAR);

		if (year != null) {
			try {
				nYear = Integer.parseInt(year);
			} catch (Exception e) {
			}
		}
		StringBuffer result = service.spiRunDistanceComparechartDate(nYear);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}

	public String spiRunTimeCompareChartData() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();

		String year = request.getParameter("year");
		Calendar instance = Calendar.getInstance();
		int nYear = instance.get(Calendar.YEAR);

		if (year != null) {
			try {
				nYear = Integer.parseInt(year);
			} catch (Exception e) {
			}
		}
		StringBuffer result = service.spiRunTimeComparechartDate(nYear);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}

	public String unitRunDistanceCompareChartData() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();

		String year = request.getParameter("year");
		Calendar instance = Calendar.getInstance();
		int nYear = instance.get(Calendar.YEAR);

		if (year != null) {
			try {
				nYear = Integer.parseInt(year);
			} catch (Exception e) {
			}
		}
		StringBuffer result = service.unitRunDistanceComparechartDate(nYear);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}

	public String unitRunTimeCompareChartData() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();

		String year = request.getParameter("year");
		Calendar instance = Calendar.getInstance();
		int nYear = instance.get(Calendar.YEAR);

		if (year != null) {
			try {
				nYear = Integer.parseInt(year);
			} catch (Exception e) {
			}
		}
		StringBuffer result = service.unitRunTimeComparechartDate(nYear);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}
	
	
	public String oilWearChartData() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		String devCode = request.getParameter("devCode");

		StringBuffer result = service.oilWearChartData(devCode);

		// 添加bom
		byte[] utf8Bom = new byte[] { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
		String utf8BomStr = "";
		try {
			utf8BomStr = new String(utf8Bom, "UTF-8");// 定义BOM标记
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		result.insert(0, utf8BomStr);

		this.inputStream = new ByteArrayInputStream(result.toString().getBytes(
				"utf-8"));

		return SUCCESS;
	}
	public void downloadWord() {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		UserInfo userInfo = (UserInfo)session.getAttribute("userInfo");

		String devCode = request.getParameter("devCode");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Content-Type", "application/force-download");
		response.setHeader("Content-Type", "application/msword");
		response
				.setHeader("Content-Disposition", "attachment;filename=abc.doc");
		Document document = new Document(PageSize.A4);// 创建word文档,并设置纸张的大小
		try {
			RtfWriter2.getInstance(document, response.getOutputStream());
			document.open();
			// 开始设置内容
			List<Map> baseInfo = service.get_JK_baseInfo(devCode);
			Map map01 = baseInfo.get(0);
			Map map02 = baseInfo.get(1);
			String danwei = null;
			String mingcheng = null;
			String gongsi = null;
			String leixing = null;
			String touchanYear = null;
			String jiashiyuan = null;
			String touchanMD = null;
			String leijiXiaoshi =null;
			String leijiGongli = null;
			String weihuDate = null;
			String weihuNeirong = null;
			
			
			// 设置第一段
			if (map01 != null) {
				mingcheng = map01.get(1).toString();
				leixing = map01.get(2).toString();
				danwei = map01.get(3).toString();
				String temp = map01.get(4).toString();
				touchanYear = temp.substring(0,4);
				touchanMD =temp.substring(5,7)+"月"+temp.substring(8,10)+"日";
				jiashiyuan =map01.get(5).toString();
			} 
			
			if(map02!=null){
				weihuDate =map02.get(1).toString();
				weihuNeirong =map02.get(2).toString();
				leijiXiaoshi = map02.get(3).toString();
				leijiGongli = map02.get(4).toString();
			}
			
			setParagraph(document, (danwei==null?"XX":danwei)+"单位"+(mingcheng==null?"XX":mingcheng)+"设备（" + startDate.substring(0,11) + "~"
					+ endDate.substring(0,11) + "）健康报表", Paragraph.ALIGN_CENTER, 0, 0, 0,
					22, "宋体", Font.NORMAL);

			// 设置第二段
			setParagraph(document, "一、 基本信息", Paragraph.ALIGN_LEFT, 0, 0,
					0, 11, "微软雅黑", Font.BOLD);

			// 设置第三段
			setParagraph(document,devCode+"（设备牌照），隶属于"+(gongsi==null?"XX":gongsi)+"公司，属"+(leixing==null?"XX":leixing)+"类型设备，于"+(touchanYear==null?"XX":touchanYear)+"年投产，现驾驶员为"+(jiashiyuan==null?"XX":jiashiyuan)+",设备自"+(touchanMD==null?"XX":touchanMD)+"至今，已累计运行"+(leijiXiaoshi==null?"XX":leijiXiaoshi)+"小时，行驶"+(leijiGongli==null?"XX":leijiGongli)+"公里，于"+(weihuDate==null?"XX":weihuDate.substring(0,11))+"进行维护，维护内容为"+(weihuNeirong==null?"XX":weihuNeirong)+"。",
							Paragraph.ALIGN_LEFT, 30, 30, 0, 11, "微软雅黑",
							Font.NORMAL);

			// 第四段
			setParagraph(document, "二、 工作简报", Paragraph.ALIGN_LEFT, 0, 0, 0, 11, "微软雅黑", Font.BOLD);
			
			
			List<Map> jianBao = service.get_JK_jianBao(devCode, startDate, endDate);
			
			String ljgs = null;
			String rjgs = null;
			String zggs = null;
			String zggssj = null;
			String zdgs = null;
			String zdgssj = null;
			String ljlc = null;
			String rjlc = null;
			String zglc = null;
			String zglcsj = null;
			String zdlc = null;
			String zdlcsj = null;
			String ljyh = null;
			String rjyh  = null;
			String zgyh = null;
			String zgyhsj = null;
			String zdyh = null;
			String zdyhsj = null;
			String pjwd = null;
			String rzgwd = null;
			String rzgwdsj = null;
			String rzdwd = null;
			String rzdwdsj = null;
			
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date1 = sdf.parse(startDate);
			Date date2 = sdf.parse(endDate);
			
			long tianshu = (date2.getTime()-date1.getTime())/(1000*24*60*60);
			
			Map map03 = jianBao.get(0);
			//检测是否存在数据
			if(map03!=null){
				if(map03.get(1)==null||map03.get(2)==null||map03.get(3)==null||map03.get(4)==null){
					
					setParagraph(document, "无显示数据。",
							Paragraph.ALIGN_LEFT, 0, 0, 0, 13, "微软雅黑", Font.NORMAL);
					document.close();
					return;
				}
			}
			
			if(map03!=null){
				ljgs = map03.get(1).toString();
				ljlc = map03.get(2).toString();
				ljyh = map03.get(3).toString();
				pjwd = map03.get(4).toString();
				
				rjgs = ( Double.parseDouble(ljgs)/tianshu)+"";
				rjlc = (Double.parseDouble(ljlc)/tianshu)+"";
				rjyh = (Double.parseDouble(ljyh)/tianshu)+"";
			}
			Map map04 = jianBao.get(1);
			if(map04!=null){
				zggs = map04.get(1).toString();
				zggssj = map04.get(2).toString();
			}
			
			Map map05 = jianBao.get(2);
			if(map05!=null){
				zdgs = map05.get(1).toString();
				zdgssj = map05.get(2).toString();
			}
			
			Map map06 = jianBao.get(3);
			if(map06!=null){
				zglc = map06.get(1).toString();
				zglcsj = map06.get(2).toString();
			}
			
			Map map07 = jianBao.get(4);
			if(map07!=null){
				zdlc = map07.get(1).toString();
				zdlcsj = map07.get(2).toString();
			}
			
			Map map08 = jianBao.get(5);
			if(map08!=null){
				zgyh = map08.get(1).toString();
				zgyhsj = map08.get(2).toString();
			}
			
			Map map09 = jianBao.get(6);
			if(map09!=null){
				zdyh = map09.get(1).toString();
				zdyhsj = map09.get(2).toString();
			}
			
			Map map10 = jianBao.get(7);
			if(map10!=null){
				rzgwd = map10.get(1).toString();
				rzgwdsj = map10.get(2).toString();
			}
			
			Map map11 = jianBao.get(8);
			if(map11!=null){
				rzdwd = map11.get(1).toString();
				rzdwdsj = map11.get(2).toString();
			}
			
			// 第五段
			setParagraph(document, "累计工时："+(ljgs==null?"XX":ljgs)+"  日均工时："+(rjgs==null?"XX":rjgs),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);

			// 第六段
			setParagraph(document,"最高工时："+(zggs==null?"XX":zggs)+" 时间： "+(zggssj==null?"XX":zggssj)+" 最低工时："+(zdgs==null?"XX":zdgs)+" 时间： "+(zdgssj==null?"XX":zdgssj),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第七段
			setParagraph(document, "累计里程："+(ljlc==null?"XX":ljlc)+" 日均里程： "+(rjlc==null?"XX":rjlc),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第八段
			setParagraph(document,
					"最高里程："+(zglc==null?"XX":zglc)+" 时间: "+(zglcsj==null?"XX":zglcsj)+"最低里程："+(zdlc==null?"XX":zdlc)+"  时间: "+(zdlcsj==null?"XX":zdlcsj),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第九段
			setParagraph(document, "累计油耗："+(ljyh==null?"XX":ljyh)+"  日均油耗："+(rjyh==null?"XX":rjyh),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第十段
			setParagraph(document,
					"最高油耗："+(zgyh==null?"XX":zgyh)+"  时间"+(zgyhsj==null?"XX":zgyhsj)+" 最低油耗："+(zdyh==null?"XX":zdyh)+"  时间"+(zdyhsj==null?"XX":zdyhsj),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第十一段
			setParagraph(document,
					"平均温度："+(pjwd==null?"XX":pjwd)+"  日最高温度："+(rzgwd==null?"XX":rzgwd)+"  发生时间"+(rzgwdsj==null?"XX":rzgwdsj),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第十二段
			setParagraph(document, "日最低温度："+(rzdwd==null?"XX":rzdwd)+"  发生时间"+(rzdwdsj==null?"XX":rzdwdsj),
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			
			
			
			
			// 第十三段
			setParagraph(document, "三、 同类设备对比", Paragraph.ALIGN_LEFT, 0, 0,
					0, 11, "微软雅黑", Font.BOLD);
			
			
			List<Map> sbdb = service.get_JK_sbdb(devCode,startDate,endDate,(int)tianshu);
			String tlxpjgs = null;
			String tlxpjlc = null;
			String tlxpjyh = null;
			String tlxpjwd = null;
			
			Map map12 = sbdb.get(0);
			if(map12!=null){
				tlxpjgs = map12.get(1).toString();
				tlxpjlc = map12.get(2).toString();
				tlxpjyh = map12.get(3).toString();
				tlxpjwd = map12.get(4).toString();
			}
			
			Map map13 = sbdb.get(1);
			String gsInt = map13.get("gsInt").toString();
			String lcInt = map13.get("lcInt").toString();
			String yhInt = map13.get("yhInt").toString();
			String wdInt = map13.get("wdInt").toString();

			// 第十四段
			setParagraph(document, "日工时方面，同类设备的平均日工时"+(tlxpjgs==null?"XX":tlxpjgs)+"小时，同类设备中排名"+gsInt+".",
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第十五段
			setParagraph(document, "日里程方面，同类设备的平均日里程"+(tlxpjlc==null?"XX":tlxpjlc)+"千米，同类设备中排名"+lcInt+".",
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第十六段
			setParagraph(document, "日油耗方面，同类设备的平均日油耗"+(tlxpjyh==null?"XX":tlxpjyh)+"升，同类设备中排名"+yhInt+".",
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);
			// 第十七段
			setParagraph(document, "工作温度方面，同类设备的平均温度"+(tlxpjwd==null?"XX":tlxpjwd)+"°，同类设备中排名"+wdInt+".",
					Paragraph.ALIGN_LEFT, 0, 30, 0, 11, "微软雅黑", Font.NORMAL);

			// 第十八段
			setParagraph(document, "四、 健康评分及趋势", Paragraph.ALIGN_LEFT, 0,
					0, 0, 11, "微软雅黑", Font.BOLD);
			
			List<Map> sbpf = service.get_JK_sbpf(devCode,startDate,endDate);
			Map map14 = null;
			if(sbpf.size()>0){
				map14 = sbpf.get(0);
			}
			String pm = "-1";
			String fs = "0";
			
			if(map14!=null){
				pm = map14.get(1).toString();
				fs = map14.get(2).toString();
			}
			
			// 第十九段
			setParagraph(
							document,
							"在参考同类设备的能耗产能比后，该设备的健康分数为"+(fs)+"分,同类设备中排名 第"+(pm)+".",
							Paragraph.ALIGN_LEFT, 30, 0, 0, 11, "微软雅黑",
							Font.NORMAL);
			// 第二十段
			setParagraph(document, "统计日期："+startDate.substring(0,11)+"~"+endDate.substring(0,11),
					Paragraph.ALIGN_RIGHT, 0, 0, 0, 11, "微软雅黑", Font.NORMAL);
			
			
			
			// 第二十一段
			setParagraph(document, "统  计  人："+userInfo.getUserName(), Paragraph.ALIGN_RIGHT,
					0, 0, 60, 11, "微软雅黑", Font.NORMAL);

			// 设置内容结束
			document.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @param doc
	 *            文档
	 * @param content
	 *            段落内容
	 * @param align
	 *            段落对齐方式
	 * @param indentationFirstLine
	 *            首行缩进
	 * @param indentationLeft
	 *            左缩进
	 * @param indentationRight
	 *            右缩进
	 * @param fontSize
	 *            文字大小
	 * @param fontFamily
	 *            字体
	 * @param fontStyle
	 *            字体样式
	 * @throws DocumentException
	 */
	private void setParagraph(Document doc, String content, int align,
			float indentationFirstLine, float indentationLeft,
			float indentationRight, float fontSize, String fontFamily,
			int fontStyle) throws DocumentException {
		Paragraph paragraph = new Paragraph(content);
		paragraph.setAlignment(align);
		paragraph.setFirstLineIndent(indentationFirstLine);
		paragraph.setIndentationLeft(indentationLeft);
		paragraph.setIndentationRight(indentationRight);

		paragraph.setSpacingBefore(10);

		Font font = new Font();
		font.setSize(fontSize);
		font.setFamily(fontFamily);
		font.setStyle(fontStyle);
		paragraph.setFont(font);
		doc.add(paragraph);
	}
	

	public String showJiankang() throws ParseException{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		UserInfo userInfo = (UserInfo)session.getAttribute("userInfo");

		String devCode = request.getParameter("devCode");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date1 = sdf.parse(startDate);
		Date date2 = sdf.parse(endDate);
		
		long tianshu = (date2.getTime()-date1.getTime())/(1000*24*60*60);
		
		List<Map> baseInfo = service.get_JK_baseInfo(devCode);
		Map map01 = baseInfo.get(0);
		Map map02 = baseInfo.get(1);
		String danwei = null;
		String mingcheng = null;
		String gongsi = null;
		String leixing = null;
		String touchanYear = null;
		String jiashiyuan = null;
		String touchanMD = null;
		String leijiXiaoshi =null;
		String leijiGongli = null;
		String weihuDate = null;
		String weihuNeirong = null;
		
		
		// 设置第一段
		if (map01 != null) {
			mingcheng = map01.get(1).toString();
			leixing = map01.get(2).toString();
			danwei = map01.get(3).toString();
			String temp = map01.get(4).toString();
			touchanYear = temp.substring(0,4);
			touchanMD =temp.substring(5,7)+"月"+temp.substring(8,10)+"日";
			jiashiyuan =map01.get(5).toString();
		} 
		
		if(map02!=null){
			weihuDate =map02.get(1).toString();
			weihuNeirong =map02.get(2).toString();
			leijiXiaoshi = map02.get(3).toString();
			leijiGongli = map02.get(4).toString();
		}
		
		
		
		
		
		
		List<Map> jianBao = service.get_JK_jianBao(devCode, startDate, endDate);
		Map map03 = jianBao.get(0);
		//检测是否存在数据
		if(map03!=null){
			if(map03.get(1)==null||map03.get(2)==null||map03.get(3)==null||map03.get(4)==null){
				return INPUT;
			}
		}
		String ljgs = null;
		String rjgs = null;
		String zggs = null;
		String zggssj = null;
		String zdgs = null;
		String zdgssj = null;
		String ljlc = null;
		String rjlc = null;
		String zglc = null;
		String zglcsj = null;
		String zdlc = null;
		String zdlcsj = null;
		String ljyh = null;
		String rjyh  = null;
		String zgyh = null;
		String zgyhsj = null;
		String zdyh = null;
		String zdyhsj = null;
		String pjwd = null;
		String rzgwd = null;
		String rzgwdsj = null;
		String rzdwd = null;
		String rzdwdsj = null;
		
		
		if(map03!=null){
			ljgs = map03.get(1).toString();
			ljlc = map03.get(2).toString();
			ljyh = map03.get(3).toString();
			pjwd = map03.get(4).toString();
			
			rjgs = ( Double.parseDouble(ljgs)/tianshu)+"";
			rjlc = (Double.parseDouble(ljlc)/tianshu)+"";
			rjyh = (Double.parseDouble(ljyh)/tianshu)+"";
		}
		Map map04 = jianBao.get(1);
		if(map04!=null){
			zggs = map04.get(1).toString();
			zggssj = map04.get(2).toString();
		}
		
		Map map05 = jianBao.get(2);
		if(map05!=null){
			zdgs = map05.get(1).toString();
			zdgssj = map05.get(2).toString();
		}
		
		Map map06 = jianBao.get(3);
		if(map06!=null){
			zglc = map06.get(1).toString();
			zglcsj = map06.get(2).toString();
		}
		
		Map map07 = jianBao.get(4);
		if(map07!=null){
			zdlc = map07.get(1).toString();
			zdlcsj = map07.get(2).toString();
		}
		
		Map map08 = jianBao.get(5);
		if(map08!=null){
			zgyh = map08.get(1).toString();
			zgyhsj = map08.get(2).toString();
		}
		
		Map map09 = jianBao.get(6);
		if(map09!=null){
			zdyh = map09.get(1).toString();
			zdyhsj = map09.get(2).toString();
		}
		
		Map map10 = jianBao.get(7);
		if(map10!=null){
			rzgwd = map10.get(1).toString();
			rzgwdsj = map10.get(2).toString();
		}
		
		Map map11 = jianBao.get(8);
		if(map11!=null){
			rzdwd = map11.get(1).toString();
			rzdwdsj = map11.get(2).toString();
		}
		
		
		
		
		
		List<Map> sbdb = service.get_JK_sbdb(devCode,startDate,endDate,(int)tianshu);
		String tlxpjgs = null;
		String tlxpjlc = null;
		String tlxpjyh = null;
		String tlxpjwd = null;
		
		Map map12 = sbdb.get(0);
		if(map12!=null){
			tlxpjgs = map12.get(1).toString();
			tlxpjlc = map12.get(2).toString();
			tlxpjyh = map12.get(3).toString();
			tlxpjwd = map12.get(4).toString();
		}
		
		Map map13 = sbdb.get(1);
		String gsInt = map13.get("gsInt").toString();
		String lcInt = map13.get("lcInt").toString();
		String yhInt = map13.get("yhInt").toString();
		String wdInt = map13.get("wdInt").toString();
		
		
		List<Map> sbpf = service.get_JK_sbpf(devCode,startDate,endDate);
		Map map14 = null;
		if(sbpf.size()>0){
			map14 = sbpf.get(0);
		}
		String pm = "-1";
		String fs = "0";
		
		if(map14!=null){
			pm = map14.get(1).toString();
			fs = map14.get(2).toString();
		}
		
		
		request.setAttribute("danwei",danwei);
		request.setAttribute("mingcheng",mingcheng );
		request.setAttribute("startDate",startDate.substring(0,11) );
		request.setAttribute("endDate",endDate.substring(0,11) );
		request.setAttribute("devCode",devCode );
		request.setAttribute("gongsi",gongsi );
		request.setAttribute("leixing", leixing);
		request.setAttribute("touchanYear",touchanYear );
		request.setAttribute("jiashiyuan", jiashiyuan);
		request.setAttribute("touchanMD",touchanMD );
		request.setAttribute("leijiXiaoshi", leijiXiaoshi);
		request.setAttribute("leijiGongli", leijiGongli);
		request.setAttribute("weihuDate",weihuDate.substring(0,11) );
		request.setAttribute("weihuNeirong", weihuNeirong);
		

		request.setAttribute("ljgs", ljgs);
		request.setAttribute("rjgs", rjgs);
		request.setAttribute("zggs",zggs );
		request.setAttribute("zggssj",zggssj );
		request.setAttribute("zdgs", zdgs);
		request.setAttribute("zdgssj",zdgssj );
		request.setAttribute("ljlc", rjlc);
		request.setAttribute("zglc", zglc);
		request.setAttribute("zglcsj",zglcsj );
		request.setAttribute("zdlc",zdlc );
		request.setAttribute("zdlcsj", zdlcsj);
		request.setAttribute("ljyh",ljyh );
		request.setAttribute("rjyh", rjyh);
		request.setAttribute("zgyh",zgyh );
		request.setAttribute("zgyhsj", zgyhsj);
		request.setAttribute("zdyh", zdyh);
		request.setAttribute("zdyhsj",zdyhsj );
		request.setAttribute("pjwd",pjwd );
		request.setAttribute("rzgwd", rzgwd);
		request.setAttribute("rzgwdsj", rzgwdsj);
		request.setAttribute("rzdwd", rzdwd);
		request.setAttribute("rzdwdsj",rzdwdsj );
		
		request.setAttribute("tlxpjgs",tlxpjgs );
		request.setAttribute("gsInt", gsInt);
		request.setAttribute("tlxpjlc", tlxpjlc);
		request.setAttribute("lcInt",lcInt );
		request.setAttribute("tlxpjyh", tlxpjyh);
		request.setAttribute("yhInt",yhInt );
		request.setAttribute("tlxpjwd", tlxpjwd);
		request.setAttribute("wdInt",wdInt );
		
		request.setAttribute("fs", fs);
		request.setAttribute("pm", pm);
		request.setAttribute("userName", userInfo.getUserName());
		
		return SUCCESS;
	}
}
